import javax.print.DocFlavor;

/**
 * @User: vitobo
 * @Date: 2024-05-31
 * @Description: 实现一个泛型类
 *
 *  泛型没有下界
 *
 */
class Person implements Comparable<Person>{
    public int age;
    public Person(int age){
        this.age = age;
    }

    @Override
    public String toString(){
        return "Person:" +
                "age=" +age+
                '}';
    }

    @Override
    public int compareTo(Person o) {
        return this.age - o.age;
    }
}

// 泛型类
class Alg<T extends Comparable<T>>{
    public T findMax(T[] array){
        T max = array[0];
        for (int i = 0; i < array.length; i++) {
            if(max.compareTo(array[i]) < 0){
                max = array[i];
            }
        }
        return max;
    }
}


class Alg2{
    // 泛型方法
    public static<T extends Comparable<T>> T findMax(T[] array){
        T max = array[0];
        for (int i = 0; i < array.length; i++) {
            if(max.compareTo(array[i]) < 0){
                max = array[i];
            }
        }
        return max;
    }
}

public class Test2 {


    public static void main4(String[] args) {
        Integer[] array = {2,4,6,8};
        Integer ret = Alg2.<Integer>findMax(array);
        System.out.println(ret);
    }
    public static void main3(String[] args) {
        Alg<Integer> alg = new Alg<>();
        Integer[] array = {1,3,5,7};
        Integer ret = alg.findMax(array);
        System.out.println(ret);
    }

    public static void main2(String[] args) {
        Alg<Person> alg = new Alg<>();
        Person[] people = {new Person(10), new Person(20)};
        Person person = alg.findMax(people);
        System.out.println(person);
    }

    public static void main1(String[] args) {
        int[] array = {1,2,3,4};
        System.out.println(array[0] > array[1]);
    }

}
